#ifndef CONNECTWIDGET_H
#define CONNECTWIDGET_H

#include <QtCore>
#include <QPointer>

#include "ui_ConnectWidget.h"

#include "AttributeWidget.h"
#include "InfoChatWidget.h"
#include "ComponentsTreeModel.h"
#include "ConversationWidget.h"
#include "RoComponent.h"
#include "RoDebugViewerComponent.h"

#include "common.h"

class ConnectDialog : public QWidget, Ui::ConnectWidget
{
    Q_OBJECT

    typedef QWidget super;

public:
    explicit ConnectDialog(QTabWidget* parent = 0);
signals:
    void allMethodsReceived();

public slots:
    void addInfoAttribute();
    void addInfoChatWidget();
    void callFunction();
    void connectToServer();
    void deleteInfoAttribute();
    void disconnectFromServer();
    void gotAllMethods();
    void gotComponents(const QMap<QString,QString> gotComponents);
    void gotMethods(const QString& gotComponentName,const QList<Component::Function>& gotMethods);
    void gotNewInfo(const RoInfoStanza& stanza);
    void handleConnectedSignal();
    void handleTreeViewClick(const QModelIndex& clictedIndex);
    void handleTreeViewDoubleClick(const QModelIndex& doubleClictedIndex);
    void sendInfo();
    void showQueryWidget();
    void showInfoWidget();
    void tabCloseButtonPressed(int tabIndex);

private:
    bool closeOtherTabs();
    void getComponents();

    void setActions();
    void setInitialData();

    void setTextWithCursorInBegin(QLineEdit* const lineEdit, const QString& text);

private:

    QPointer<RoComponent> m_component;
    QPointer<ComponentsTreeModel> m_model;
    QPointer<RoModule> m_module;

    QString m_chosenComponent;
    QString m_chosenMethod;

    int amountOfComponents;
    QList<Component> modelItems;
    QTabWidget* parentTabWidget;

    QMap< QString, QPointer<ConversationWidget> > infoReceivers;
    QMap< QString, QPointer<InfoChatWidget> >infoChatReceivers;
    QList<AttributeWidget*> attributeWidgets;
};

#endif // CONNECTWIDGET_H
